package com.example.demo.controller;

import com.example.demo.common.RedisUtil;
import com.example.demo.entity.TestUser;
import com.example.demo.service.TestUserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class TestUserController {

    @Autowired
    private TestUserService testUserService;
    @Autowired
    private RedisUtil redisUtil;

    @RequestMapping(value = "/api/city", method = RequestMethod.GET)
    public TestUser findOneCity(@RequestParam(value = "id", required = true) Integer id) {
        /*return testUserService.getTestUser(id);*/
        return new TestUser();
    }

    @RequestMapping(value = "/api/rabbitMq", method = RequestMethod.GET)
    public String findRabbitMq(@RequestParam(value = "id", required = true) Integer id) {
        testUserService.sendRabbitMq("exchange", "routingKey", "hello world");
        return "ssss";
    }

    @RequestMapping(value = "/api/redis", method = RequestMethod.GET)
    public TestUser findRedis(@RequestParam(value = "id", required = true) Integer id) {
        /*return testUserService.getTestUser(id);*/
        if(id==1){
            redisUtil.set("116405407AX1017103E0258D","116405407AX1017103E0258D");
        }
        if (id==2){
            String sssss = redisUtil.get("116405407AX1017103E0258D");
            System.out.println(sssss);
        }
        if (id==3){
            redisUtil.delete("116405407AX1017103E0258D");
        }
        return new TestUser();
    }
}
